﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.fmtx.IDal;
using com.fmtx.Model;

namespace com.fmtx.Dal
{
    public class KeyWordServer:BaseServer<KeyWord>,IKeyWord
    {
        public bool IsExists(string keyword,Target tag)
        {
            var res = db.AllList(w=>w.Keyword==keyword&&w.Tag==tag).FirstOrDefault();
            if (res != null && res.Id > 0)
            {
                res.HostNum++;
                db.Update(res);
            }
            else {
                KeyWord model = new KeyWord();
                model.Keyword = keyword;
                model.Tag = tag;
                model.HostNum = 1;
                db.Add(model);
            }
            return true;
        }


        public IList<KeyWord> QueryHost(int size,Target tag)
        {
            return db.AllList(w=>w.Tag==tag).OrderByDescending(o=>o.HostNum).Take(size).ToList();
        }

    }
}
